package com.chengyu.core.service.ty;

import com.chengyu.core.domain.form.CaculateFreightFeeForm;
import com.chengyu.core.domain.form.OrderSearchForm;
import com.chengyu.core.domain.form.TyOrderAddForm;
import com.chengyu.core.domain.result.TyOrderPayResult;
import com.chengyu.core.domain.result.TyOrderResult;
import com.chengyu.core.domain.result.TyPayResult;
import com.chengyu.core.domain.result.TyServiceResult;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.exception.ServiceException;
import com.chengyu.core.model.*;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author LeGreen
 * @title 订单
 * @date 2022/4/29
 */
public interface TyOrderService {

    /**
     * 订单列表
     *
     * @param form
     * @param page
     * @param pageSize
     * @return CommonPage<TyOrderResult>
     * @author LeGreen
     * @date 2022/4/29
     * @date 2022/4/29
     */
    CommonPage<TyOrderResult> getOrderList(OrderSearchForm form, Integer page, Integer pageSize);

    /**
     * 订单详情
     *
     * @param orderId
     * @return TyOrderResult
     * @author LeGreen
     * @date 2022/4/29
     */
    TyOrderResult getOrder(Integer orderId);

    /**
     * 提交订单
     *
     * @param member
     * @param addressTo
     * @param addressFrom
     * @return OrderPayResult
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/4/29
     */
    TyOrderPayResult addOrder(UmsMember member, UmsMemberAddress addressTo, UmsMemberAddress addressFrom,ReceiptUser receiptUser, TyOrderAddForm addForm) throws ServiceException;



    /**
     * 计算运费
     *
     * @param shopId
     *
     * @param addressFrom
     * @param freightFeeFormList
     * @return BigDecimal
     * @author LeGreen
     * @date 2022/5/16
     */
    BigDecimal caculateFreightFee(Integer shopId, UmsMemberAddress addressTo, UmsMemberAddress addressFrom, List<CaculateFreightFeeForm> freightFeeFormList);

    /**
     * 支付成功
     *
     * @param payOrderNo
     * @author LeGreen
     * @date 2022/4/29
     */
    void paySus(String payOrderNo) throws ServiceException;




    /**
     * 确认收货
     *
     * @param member
     * @param orderId
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/4/29
     */
    void confirmOrder(UmsMember member, Integer orderId) throws ServiceException;



    /**
     * 完成订单
     *
     * @param order 订单
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/9/20
     */
    void finishOrder(TyOrder order) throws ServiceException;

    /**
     * 修改订单地址
     *
     * @param member
     * @param orderId
     * @param addressId
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/4/29
     */
    void updateOrderAddress(UmsMember member, Integer orderId, Integer addressId) throws ServiceException;

    /**
     * 取消待支付订单
     *
     * @param member
     * @param orderId
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/4/29
     */
    void cancelOrder(UmsMember member, Integer orderId) throws ServiceException;

    void starttransport(UmsMember member, Integer orderId) throws ServiceException;

    void endtransport(UmsMember member, Integer orderId) throws ServiceException;

    /**
     * 删除交易关闭订单
     *
     * @param member
     * @param orderId
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/4/29
     */
    void deleteOrder(UmsMember member, Integer orderId) throws ServiceException;

    /**
     * 订单超时未支付自动取消
     *
     * @param payOrderNo
     * @author LeGreen
     * @date 2022/5/5
     */
    void autoCancelOrder(String payOrderNo);

    /**
     * 订单自动确认收货
     *
     * @param orderNo
     * @author LeGreen
     * @date 2022/5/5
     */
    void autoFinishOrder(String orderNo) throws ServiceException;

    /**
     * 总后台删除订单
     *
     * @param idList
     * @author LeGreen
     * @date 2022/5/7
     */
    void deleteOrderByAdmin(List<Integer> idList);

    /**
     * 统计待发货，待收货，待评价，退款数量
     *
     * @param memberId
     * @return Map<String, Object>
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/6/2
     */
    Map<String, Object> count(Integer memberId);

    /**
     * 获取支付订单
     *
     * @param payOrderNo
     * @return CommonPayOrder
     * @author LeGreen
     * @date 2022/6/9
     */
    CommonPayOrder getPayOrder(String payOrderNo);

    /**
     * 更新订单的支付方式和支付渠道
     *
     * @param payOrderNo
     * @param payMethod
     * @param applicationType
     * @author LeGreen
     * @date 2022/6/9
     */
    void updateOrderPaymethod(String payOrderNo, String payMethod, String applicationType);

    /**
     * 查询订单
     *
     * @param orderId
     * @return TyOrder
     * @author LeGreen
     * @date 2022/6/9
     */
    TyOrder getOrderById(Integer orderId);

    /**
     * 根据订单号查询订单
     *
     * @param orderNo
     * @return TyOrder
     * @author LeGreen
     * @date 2022/6/9
     */
    TyOrder getOrderByOrderNo(String orderNo);
    TyOrder getOrderByPayOrderNo(String payOrderNo);

    /**
     * 取消订单成功
     *
     * @param order
     * @throws ServiceException 业务异常
     * @author LeGreen
     * @date 2022/6/9
     */
    void cancelAndRefundOrderSus(TyOrder order);

    List<TyService> getTyService(String orderNo);

    TyServiceResult selectTyService(UmsMember member, String orderNo, Integer type) throws ServiceException;

     TyPayResult createPay(UmsMember member, String orderNo,Integer quoteId) throws ServiceException;

     TyPayResult createPay(UmsMember member,Integer quoteId ,Integer  priceId) throws ServiceException;

    TyPayResult createAddPay(UmsMember member,TyOrder order,BigDecimal amount) throws ServiceException;


    CommonPage<TyOrderResult> getMyChaseList(Integer memberId, Integer page, Integer pageSize);
}
